{% extends "projects/base.html" %}

{% load i18n %}
{% load uni_form_tags %}
{% load account_tags %}
{% load avatar_tags %}
{% load threadedcommentstags %}
{% load pagination_tags %}
{% load extra_tagging_tags %}
{% load projects_tags %}
{% load group_tags %}
{% load topics_tags %}
{% load wakawaka_tags %}
{% load theme_tags %}

{% block head_title %}{{ project.name }}{% endblock %}

{% block body %}
    
    {% if user.is_authenticated %}
        <div class="right_panel">
            <div class="members">
                <h2>{% trans "Members" %}</h2>
                <table width="100%">
                    {% for member in project.members.all %}
                        {% if forloop.counter0|divisibleby:"3" %}<tr>{% endif %}
                        <td>
                            <div class="avatar">{% avatar member.user 40 %}</div>
                            <div class="details"><a href="{% url profile_detail member.user.username %}" title="{% user_display member.user %}">{% user_display member.user %}</a></div>
                        </td>
                        {% if forloop.counter0|add:"1"|divisibleby:"3" %}</tr>{% endif %}
                    {% endfor %}
                    {% if project.members.all|length|divisibleby:"3" %}{% else %}</tr>{% endif %}
                </table>
            </div>
        </div>
    {% endif %}
    
    <div style="width: 550px;">
        
        <h1>{% trans "Project" %} {{ project.name }}</h1>
        
        <p>
            {% trans "Slug:" %} <tt>{{ project.slug }}</tt><br />
            {% trans "Creator:" %} <a href="{% url profile_detail project.creator.username %}">{% user_display project.creator %}</a><br />
            {% trans "Created:" %} {{ project.created|date }}
            <br />
            {% show_tags_for project %}
        </p>
        
        <p>{{ project.description }}</p>
        
        {% ifequal user project.creator %}
            <div class="form-toggle">
                <p><span id="edit-project-toggle">{% trans "Edit details" %}</span></p>
                
                <form class="uniForm" id="edit-project" method="POST" action="">
                    {% csrf_token %}
                    <fieldset class="inlineLabels">
                        {{ project_form|as_uni_form }}
                        <div class="form_block">
                            <input type="hidden" name="action" value="update" />
                            <input type="submit" value="{% trans "updated" %}"/>
                        </div>
                    </fieldset>
                </form>
            </div>
            
        {% endifequal %}
        
        {% if user.is_authenticated %}
            <div>
                {% if is_member %}
                    {% ifequal user project.creator %}
                        <p>You are the creator of this project.</p>
                        
                        <div class="form-toggle">
                            <p><span id="add-member-toggle">{% trans "Add new member" %}</span></p>
                            
                            <form class="uniForm" id="add-member" method="POST" action="">
                                {% csrf_token %}
                                <fieldset class="inlineLabels">
                                    {{ adduser_form|as_uni_form }}
                                    <div class="form_block">
                                        <input type="hidden" name="action" value="add" />
                                        <input type="submit" value="{% trans "add" %}"/>
                                    </div>
                                </fieldset>
                            </form>
                        </div>
                        
                        <p>{% silk "delete" %} <a href="#" onclick="$('#delete_project_form').toggle(); return false;">{% trans "Delete project" %}</a><p>
                         <form class="delete_form" id="delete_project_form" action="{% url project_delete project.slug %}" method="POST" style="display: none;">
                             {% csrf_token %}
                             <input type="submit" value="{% trans "Delete Project" %}" /> (all content will be removed)
                        </form>
                    {% else %}
                        <p>You are member of this project.</p>
                    {% endifequal %}
                {% else %}
                    <p>It is up to the creator of this project (<a href="{% url profile_detail project.creator.username %}">{% user_display project.creator %}</a>) to add you.</p>
                {% endif %}
            </div>
        {% endif %}
        
        {% if user.is_authenticated %}
            <h2>{% trans "Discussion Topics" %}{% if project.topics.all.count %} ({{ project.topics.all.count }}){% endif %}</h2>
            
            {% get_topics_for_group project as topic_queryset %}
            {% with topic_queryset|slice:":5" as topics %}
                {% if topics %}
                    {% for topic in topics|slice:":5" %}
                        {% show_topic topic %}
                    {% endfor %}
                    <p><a href="{% groupurl topic_list project %}">{% trans "more..." %}</a></p>
                {% else %}
                    {% groupurl topic_list project as new_topic_url %}
                    <p>{% blocktrans %}None yet. <a href="{{ new_topic_url }}">Start one...</a>{% endblocktrans %}</p>
                {% endif %}
            {% endwith %}
            
            {% content_objects project "wakawaka.WikiPage" as articles %}
            <h2>{% trans "Wiki Articles" %}{% if articles %} ({{ articles|length }}){% endif %}</h2>
            
            {% if articles %}
                <table class="topics">
                    {% for article in articles %}
                        {{ article }}
                    {% endfor %}
                </table>
                <p><a href="{% groupurl wakawaka_page_list project %}">{% trans "more..." %}</a></p>
            {% else %}
                {% groupurl wakawaka_page_list project as wiki_url %}
                <p>
                    {% blocktrans %}
                        None yet. Go to the <a href="{{ wiki_url }}" title="wiki">wiki</a> to start a new article.
                    {% endblocktrans %}
                </p>
            {% endif %}
            
            <h2>{% trans "Tasks" %}</h2>
            
            {% groupurl task_list project as tasks_url %}
            <p>More here soon but, in the meantime, here's a link to the <a href="{{ tasks_url }}">task list</a>.</p>
            
            <h2>Knowledge Base</h2>
            
            <a href="{% groupurl knowledge_base_index project %}">Go</a> to knowledge base index.
                        
        {% endif %}
    </div>

{% endblock %}

{% block extra_body %}
    <script type="text/javascript">
        $(document).ready(function() {
            $('#edit-project').hide();
            $('#edit-project-toggle').click(function() {
                $('#edit-project').toggle();
                $('#edit-project').autoscroll();
                return false;
            });
            if ($('#edit-project .error').length) {
                $('#edit-project').show();
                $('#edit-project .error').autoscroll();
            }
            $('#add-member').hide();
            $('#add-member-toggle').click(function() {
                $('#add-member').toggle();
                $('#add-member').autoscroll();
                return false;
            });
            if ($('#add-member .error').length) {
                $('#add-member').show();
                $('#add-member .error').autoscroll();
            }
        });
    </script>
    
{% endblock %}
